;layui.define(function (e) {
  var urls = {
    countOfDays: '/winchat/user/countOfDays'
  };
  layui.use(["http", "carousel"], function () {
    var $ = layui.$
      , carousel = (layui.carousel)
      , a = layui.element
      , http = layui.http
      , device = layui.device();
    $(".layadmin-carousel").each(function () {
      var a = $(this);
      carousel.render({
        elem: this,
        width: "100%",
        arrow: "none",
        interval: a.data("interval"),
        autoplay: a.data("autoplay") === !0,
        trigger: device.ios || device.android ? "click" : "hover",
        anim: a.data("anim")
      })
    }), a.render("progress");
  }), layui.use(["http", "carousel", "echarts"], function () {
    var e = layui.$, t = layui.carousel, a = layui.echarts, http = layui.http, i = [], l = [];
    var params = {
      'winchatType': 'wx',
      'days': 7
    };
    http.post({
      url: urls.countOfDays, data: params, success: function (r) {
        console.log(r);
        //关注情况查询
        if (!r.data.countSubscribesModel) {
          r.data.countSubscribesModel = {
            totalSubscribes: 0,
            totalMaleSubscribes: 0,
            totalFemaleSubscribes: 0
          };
        }
        e('#totalSubscribes').html(r.data.countSubscribesModel.totalSubscribes);
        e('#curMonthSubscribes').html(r.data.countSubscribesModel.totalMaleSubscribes);
        e('#curMonthUnsubscribes').html(r.data.countSubscribesModel.curMonthUnsubscribes);
        // 七日关注/粉丝男女比例
        var dates = [], subscribes = [];
        e.each(r.data.countOfDays, function (i, item) {
          dates.push(item.date);
          subscribes.push(item.subscribes);
        });
        l = [{
          title: {text: "最近一周新增的关注量", x: "center", textStyle: {fontSize: 14}},
          tooltip: {trigger: "axis", formatter: "{b}<br>新增关注：{c}"},
          xAxis: [{type: "category", data: dates}],
          yAxis: [{type: "value"}],
          series: [{type: "line", data: subscribes}]
        }, {
          title: {text: "粉丝男女比例", x: "center", textStyle: {fontSize: 14}},
          tooltip: {trigger: "item", formatter: "{a} <br/>{b} : {c} ({d}%)"},
          legend: {orient: "vertical", x: "left", data: ["男", "女"]},
          series: [{
            name: "粉丝性别比例",
            type: "pie",
            radius: "55%",
            center: ["50%", "50%"],
            data: [
              {value: r.data.countSubscribesModel.totalMaleSubscribes, name: "男"},
              {value: r.data.countSubscribesModel.totalFemaleSubscribes, name: "女"}]
          }]
        }], n = e("#LAY-index-dataview").children("div"), r = function (e) {
          i[e] = a.init(n[e], layui.echartsTheme), i[e].setOption(l[e]), window.onresize = i[e].resize
        };
        if (n[0]) {
          r(0);
          var o = 0;
          t.on("change(LAY-index-dataview)", function (e) {
            r(o = e.index)
          }), layui.admin.on("side", function () {
            setTimeout(function () {
              r(o)
            }, 300)
          }), layui.admin.on("hash(tab)", function () {
            layui.router().path.join("") || r(o)
          })
        }
      }
    });
    
  }), layui.use(["http","laytpl"], function () {
    var e = layui.$,http= layui.http,laytpl = layui.laytpl;
    //今日菜单统计
    var params = {
      'winchatType': 'wx',
      'date': new Date().format('yyyy-MM-dd'),
      'top': 10
    };
    http.post({
      url: '/winchat/menu/click/getTops', data: params, success: function (r) {
        var getTpl = e('#tableData').html()
          , view = e('#todayClick tbody');
        laytpl(getTpl).render(r.data, function (html) {
          view.html(html);
        });
      }
    });
    //历史菜单统计
    params = {
      'winchatType': 'wx',
      'top': 10
    };
    http.post({
      url: '/winchat/menu/click/getTops', data: params, success: function (r) {
        var getTpl = e('#tableData').html()
          , view = e('#historyClick tbody');
        laytpl(getTpl).render(r.data, function (html) {
          view.html(html);
        });
      }
    });
  }), e("userStat", {})
});